#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>

MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("Manik Singhal");
MODULE_DESCRIPTION("Sample hello-world module");


/*
* Parameters accepted by module.
* Initialize with default values
*
* module_param(name, type, permission):
* Default types acceptable by module
* bool, invbool, charp, int, long, short,
* uint, ulong, ushort
*
* permission: S_IRUGO: cannot be changed by world
* S_IRUGO|S_IWUSR: root can change the parameter
* (if permission != 0, parameter appears in /sys/module*,
*  can be changed there)
*/
static char *greetings_to = "world";
static int num_greetings = 2;
module_param(greetings_to, charp, S_IRUGO);
module_param(num_greetings, int, S_IRUGO);
// google module_param_array for accepting array parameters


/*
* MODULE initialization function
*
* __init prefix: This function is required only
*      at load time, so can be dropped by loader
*      when loading the driver in memory
*/
static int __init hello_init(void) {
  int i = 0;
  for (i = 0; i < num_greetings; i++) {
      // Watch /var/log/syslog for printk in action
      printk("<1> Hello %s\n", greetings_to);
  }
  return 0;
}


/*
* Module cleanup function
*
* __exit prefix: Function required only while
*      unloading the module. So if the module is
*      built within the kernel, or the kernel does
*      not allow unloading modules, then this function
*      is discarded
*/
static void hello_exit(void) {
  printk("<1> Bye, cruel world\n");
}


/*
* Specify Module init and exit functions
*/
module_init(hello_init);
module_exit(hello_exit);
